<?php
    $url = new Url();
    $arr_region = LoadConfig::$region;
?>
<link rel="stylesheet" type="text/css" href="<?php echo Yii::app()->params['static_url'];?>css/css/color/colorpicker.css">
<link rel="stylesheet" type="text/css" href="<?php echo Yii::app()->params['static_url'];?>css/css/color/layout.css">
<script type="text/javascript" src="<?php echo Yii::app()->params['static_url'];?>js/colorpicker.js"></script>
<script type="text/javascript" src="<?php echo Yii::app()->params['static_url'];?>js/eye.js"></script>
<script type="text/javascript" src="<?php echo Yii::app()->params['static_url'];?>js/utils.js"></script>
<script type="text/javascript">

    $(document).ready(function() {

        $('#chenkq').addClass('active');

        chentest();
        chencode();

        $('#tinh').change(function(){
            chentest();
            chencode();
        })

        $('#width').change(function(){
            chentest();
            chencode();
        });

        $('#fsize').change(function(){
            chentest();
            chencode();
        });

        $('#back_color, #title_color, #db_color').ColorPicker({
            onSubmit: function(hsb, hex, rgb, el) {
                $(el).val(hex);
                $(el).ColorPickerHide();
            },
            onBeforeShow: function () {
                $(this).ColorPickerSetColor(this.value);
            }
        }).bind('keyup', function(){
            $(this).ColorPickerSetColor(this.value);
        });

        $('.colorpicker_submit').click(function(){
            var color = $('.colorpicker_hex input').val();
            //alert(color);
            $('#back_color').css('background','#'+color);
            var text = $('.colorpicker_hsb_b input').val();
            //alert(value);
            if(text>60){
                $('#back_color').css('color','black');
            }else{
                $('#back_color').css('color','white');
            }
            chentest();
            chencode();
        });

        loadChat("<?=$url->createUrl('home/chat')?>");

        $('.From').keypress(function(e){
            if(e.keyCode == 13 && !e.shiftKey){
                $(this).trigger("enterKey");
            } 
        });

        $('textarea').bind("enterKey",function(e){
            var messenger = $('.From').val();
            var url = "<?=$url->createUrl('home/chat'); ?>";
            $.ajax({
                type: "GET",
                url: url,
                global: false,
                data: {
                    messenger: messenger,
                },
                success: function(msg){  
                    if(msg==1){
                        alert('Bạn phải đăng nhập để tán gẫu');
                    }
                    if(msg==0){
                        alert('Bạn chưa nhập nội dung');
                    }
                    else
                    {
                        $("#CHAT").html(msg);
                        $('.From').val('');
                    }

                }
            });
        });

    });

    function loadChat(url){
        var scroll = $('.boxCHAT').scrollTop();
        //alert(scroll);
        $.ajax({
            type: "POST",
            url: url,
            global: false,
            data:{

            },
            success:function(msg){
                $("#CHAT").html(msg);
            }
        });
    }

    function messenger(){
        var messenger = $('.From').val();
        var url = "<?=$url->createUrl('home/chat'); ?>";
        $.ajax({
            type: "GET",
            url: url,
            global: false,
            data: {
                messenger: messenger,
            },
            success: function(msg){
                if(msg==1){
                    alert('Bạn phải đăng nhập để tán gẫu');
                }
                if(msg==0){
                    alert('Bạn chưa nhập nội dung');
                }
                else
                {
                    $("#CHAT").html(msg);
                    $('.From').val('');
                } 
            }
        });
    };

    function chentest(){
        var url = "<?=$url->createUrl('tienich/nhungview'); ?>";
        var back_color = $('#back_color').val();
        var width = $('#width').val();
        var fsize = $('#fsize').val();
        var tinh = $('#tinh').val();
        //alert(width);
        $.ajax({
            type: "GET",
            url: url,
            global: false,
            data: {
                back_color: back_color,
                width: width,
                fsize: fsize,
                tinh: tinh,
            },
            success: function(msg){
                $('#NHUNG').html(msg);
            }
        });
    }


    function chenkq(tinh,back_color,width,fsize,date){
        var url = "<?=$url->createUrl('tienich/nhungview'); ?>";
        var back_color = $('#back_color').val();
        var width = $('#width').val();
        var fsize = $('#fsize').val();
        //alert(fsize);
        $.ajax({
            type: "GET",
            url: url,
            global: false,
            data: {
                back_color: back_color,
                width: width,
                fsize: fsize,
                tinh: tinh,
                date: date,
            },
            success: function(msg){
                $('#NHUNG').html(msg);
            }
        });
    }

    function chencode(){
        var url = "<?=$url->createUrl('tienich/nhungcode'); ?>";
        var back_color = $('#back_color').val();
        var width = $('#width').val();
        var fsize = $('#fsize').val();
        var tinh = $('#tinh').val();
        //alert(width);
        $.ajax({
            type: "GET",
            url: url,
            global: false,
            data: {
                back_color: back_color,
                width: width,
                fsize: fsize,
                tinh: tinh,
            },
            success: function(msg){
                $('#CODE').html(msg);
            }
        });
    }

</script>

<div class="Main">
    <div class="leftMain">
        <div class="titleCHAT">
            <h1>Chèn kết quả xổ số</h1>
        </div>
        <div class="SM">
            <table>
                <tr>
                <td width="30%"><label>Chọn tỉnh:</label></td>
                <td width="50%"><select name="1" class="boxSearch" id="tinh">
                        <?php foreach($data as $tinh){?>
                            <option value="<?php echo $tinh['id']?>"><?php echo $tinh['name']?></option>
                            <?php }?>

                    </select>
                </td>
                <tr>
                    <td width="30%"><label>Màu nền:</label></td>
                    <td width="50%">
                        <input type="text" class="boxSearch" id="back_color" value="F51046" style="background: #F51046; color: #fff;">
                    </td>
                </tr>
                <tr>
                    <td width="30%"><label>Chiều rộng:</label></td>
                    <td width="50%">
                        <input type="text" class="boxSearch" id="width" value="300" style="background: #fff;">
                    </td>
                </tr>
                <tr>
                    <td width="30%"><label>Cỡ chữ:</label></td>
                    <td width="50%">
                        <input type="text" class="boxSearch" id="fsize" value="12" style="background: #fff;">
                    </td>
                </tr>
            </table>

            <br/>

            <div class="SM" id="CODE"></div>

            <br/>

            <div class="SM" id="NHUNG" style="text-align: center;"></div>

            <div class="sms_LOTO">
                <?php echo Yii::app()->params['static_sms'];?>
            </div>
            <div class="MXH">
                <div id="fb-root" style="float: right;"></div>
                <script>(function(d, s, id) {
                    var js, fjs = d.getElementsByTagName(s)[0];
                    if (d.getElementById(id)) return;
                    js = d.createElement(s); js.id = id;
                    js.src = "//connect.facebook.net/en_US/sdk.js#xfbml=1&appId=670383849682676&version=v2.0";
                    fjs.parentNode.insertBefore(js, fjs);
                    }(document, 'script', 'facebook-jssdk'));
                </script>
                <div class="fb-like" data-href="http://10h.vn/" data-layout="standard" data-action="like" data-show-faces="false" data-share="true"></div>
            </div>
        </div>

        <div class="CHAT">

            <div class="titleCHAT">
                Tán Gẫu
            </div>

            <div class="CHATarea">
                <textarea name="CHAT" placeholder="Nhập nội dung chat" cols="50" rows="1" class="From"></textarea>
            </div>
            <div style="padding:15px 20px 20px 0; text-align:right;">
                <a href="javascript:void(0);" id="emotion"><img src="<?php echo Yii::app()->params['static_url'];?>images/xo-so-10h-icon-yahoo.png" width="22" height="22" style="padding-right:10px;"></a>
                <a href="javascript:void(0);" onclick="loadChat('<?=$url->createUrl('home/chat')?>');"><img src="<?php echo Yii::app()->params['static_url'];?>images/Refresh.png" width="22" height="22" style="padding-right:10px;" /></a>
                <input type="button" onclick="messenger();" class="button_KQ" value="Gửi">
            </div>

            <div class="boxCHAT" id="CHAT"></div>

            <?php $this->renderPartial('boxemotion');?>

        </div>

    </div>
    <div class="rightMain">

        <div class="Box" id="boxtienich">
            <?php $this->renderPartial('boxtienich');?>
        </div>

        <div class="Box" id="boxketqua">
            <?php
                $this->renderPartial('boxketqua');
            ?>
        </div>

        <div class="Box" id="boxthongke">
            <?php $this->renderPartial('boxthongke');?>
        </div>

    </div>
    <div class="both"></div>
    </div>
